<?php
/**
 * Created by PhpStorm.
 * User: 李闯
 * Date: 2020/7/5
 * Time: 9:06
 * Content:登录处理
 */

namespace app\admin\controller;


use think\Controller;
use think\Db;
use think\facade\Session;

class Login extends Controller
{
//    use ResponseJson;

    /**
     * @param null
     * content 登录页面
     */
    public function index(){
        //$result = Db::table('sysset_account')->where(array('account'=>12,"password" => 23))->find();
        //dump(\think\facade\Env::get('database.hostname'));exit;

        if(input('get.active')=='login'){
            #登录页面处理操作
            $info = input('post.');
            $info['password'] = md5($info['password']);
            //dump($info);exit;
            if($info){
                $result = Db::table('sysset_account')->where(array('account'=>$info['account'],"password" => $info['password']))->find();
                if(empty($result)){
                    return array("status"=>false,'msg'=>"账号或密码不正确!");
                }else{
                    Session::set('uid',$result['id']);
                    Session::set('account',$result['account']);
                    Session::set('nikename',$result['nikename']);
                    return array('status'=>true);
                }
            }
        }else{
            #登录页面
//            phpinfo();
            return $this->fetch();
        }
    }
    /**
     * @param null
     * content 退出登录
     */
    public function out()
    {
        Session::delete('uid');
        Session::delete('account');
        Session::delete('nikename');
        return redirect('/admin/login/index');
    }

}